<extend name="Public/base" />
<block name="content">
    <div class="row" style="margin-top:5%;margin-bottom: 5%">
        <div class="medium-3 columns">
            <input type="text" id="className" style="height:33px">
        </div>
        <div class="medium-3 columns">
            <select id="exam" style="height:33px">
                <volist name="examType" id="et">
                    <option value="<{$et.dict_id}>"><{$et.val}></option>
                </volist>
            </select>
        </div>
        <div class="medium-3 columns">
            <select id="term" style="height:33px">
                <option value="第一学期">第一学期</option>
                <option value="第二学期">第二学期</option>
            </select>
        </div>
        <div>
            <buttom class="button tiny  radius" onclick="tj()">提交</buttom>
        </div>
    </div>
    <center>
        <table border="1">
            <theat>
               <th style="text-align: center;width:12rem">姓名</th>
                <th style="text-align: center;width:12rem">成绩</th>
            </theat>
            <tbody id="tb"></tbody>
            <tfoot id="tf" style="display:none">
                <td colspan="2" >
                    <buttom class="button tiny  radius" style="margin-left:40%" onclick="fz()">提交</buttom>
                </td>
            </tfoot>
        </table>
    </center>
    <script>
        function tj(){
            var a=$('#className').val();
            $.post("<{:U('Exams/getName')}>",{class:a},function(data){
                 var html='';
                for(i in data){
                    html+='<tr>'
                             +'<td style="text-align: center">'
                             +data[i].sname
                             +'</td>'
                             +'<td id="scoreAdd">'
                             +'<input type="text" name="score" style="height:25px;margin-top:8%">'
                             +'<input type="hidden" name="student_id" value="'+data[i].student_id+'">'
                             +'</td>'
                             +'</tr>'
                }
                $('#tb').html(html);
                $('#tf').show();
            });
        }
        function fz(){
            var a=$('#scoreAdd [name=score]').map(function(){return $(this).val();}).get().join(",");
            var b=$('#scoreAdd [name=student_id]').map(function(){return $(this).val();}).get().join(",");
            var data={
                    score:a,
                    id:b,
                    exam:$('#exam').val(),
                    term:$('#term').val(),
            };
            $.post("<{:U('Exams/add')}>",data,function(data){
                    alert(data);
                    $('#tb').html('');
                    $('#tf').hide();
            })
        }
    </script>
</block>